<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 1.手写map
        Array.prototype.myMap = function (fnn) {
            let newArr = []
            for (let i = 0; i < this.length; i++) {
                const datas = fnn(this[i], i, this)
                newArr.push(datas)
            }
            return newArr
        }

        let arr = [1, 2, 3, 4, 5]
        const str = arr.myMap(function (item, index, array) {
            return item += 1
        })
        console.log(str);

        // 2.手写filter

        Array.prototype.myFilter = function (fn) {
            let newArrs = []
            for (let i = 0; i < this.length; i++) {
                const strs = fn(this[i], i, this)
                if (strs) {
                    newArrs.push(this[i])
                }

            }
            return newArrs
        }

        const arr1 = [1, 2, 4, 6, 9]
        const str1 = arr1.myFilter(function (item, index, array) {
            return item > 5
        })
        console.log(str1);




    </script>
</body>

</html>